package com.umfwechat.util;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.umfwechat.common.code.RetCode;
import com.umfwechat.common.constant.CommonConsts;
import com.umfwechat.common.exception.BaseException;

//import com.umfWeChat.common.code.RetCode;
//import com.umfWeChat.common.constant.CommonConsts;
//import com.umfWeChat.common.exception.BaseException;
/*
 * ******************  类说明  *********************
 * class       :  DateTimesUtil
 * @author     :  未名
 * qian yi zhe :  renjie
 * @version    :  1.0  
 * description :  时间日期工具类
 * @see        :                        
 * ***********************************************
 */
public class DateTimesUtil {
	
	public static String formatDay8Str = "yyyyMMdd";
	public static String formatDay10Str = "yyyy-MM-dd";
	public static String formatDay11Str = "yyyy年MM月dd日";
	public static String formatDay12Str = "yyMMddHHmmss";//YYMMDDHHMMSS
	public static String formatTime14Str = "yyyyMMdd HHmmss";
	public static String formatDay14Str = "yyyyMMddHHmmss";
	public static String formatTime15Str = "yyyy-MM-dd HH:mm";
	public static String formatTime16Str = "yyyyMMdd HH:mm:ss";
	public static String formatTime18Str = "yyyy-MM-dd HH:mm:ss";
	public static String formatTime24Str = "yyyy-MM-dd HH:mm:ss.SSSSSS";
	public static String formatTime22Str = "yyyyMMdd HH:mm:ss.SSSSSS";
	public static String formatTime6Str = "HHmmss";
	public static String formatTime8Str = "HH:mm:ss";
	public static String formatTime10Str = "MMddHHmmss";
	public static String formatTimeHHmmStr = "HHmm";
	public static String formatDay6Str = "yyyyMM";
	public static String formatDay7Str = "yyyy-MM";
	
	public static String randomRpId14() {
		DateFormat format = new SimpleDateFormat(formatDay14Str);
		String formatDate = format.format(new Date());
		return formatDate.toString();
	}
	public static String date(String fmt) {
		return new SimpleDateFormat(fmt).format(new Date());
	}

	public static String date(String fmt, long t) {
		return new SimpleDateFormat(fmt).format(new Date(t));
	}

	public static String date8() {
		return new SimpleDateFormat(formatDay8Str).format(new Date());
	}

	public static String date8(Date date) {
		return new SimpleDateFormat(formatDay8Str).format(date);
	}
	public static String date8(Timestamp date) {
		return new SimpleDateFormat(formatDay8Str).format(date);
	}
	
	public static String date10() {
		return new SimpleDateFormat(formatDay10Str).format(new Date());
	}
	public static String date10(Date date) {
		return new SimpleDateFormat(formatDay10Str).format(date);
	}
	
	public static String date12() {
		return new SimpleDateFormat(formatDay12Str).format(new Date());
	}
	
	public static String datetime15(Date date) {
		return new SimpleDateFormat(formatTime15Str).format(date);
	}
	
	public static String datetime18() {
		return new SimpleDateFormat(formatTime18Str).format(new Date());
	}
	
	public static String datetime18(Date date) {
		return new SimpleDateFormat(formatTime18Str).format(date);
	}

	public static String time6() {
		return new SimpleDateFormat(formatTime6Str).format(new Date());
	}

	public static String time6(Date date) {
		return new SimpleDateFormat(formatTime6Str).format(date);
	}
	public static String time6(Timestamp date) {
		return new SimpleDateFormat(formatTime6Str).format(date);
	}

	public static String datetime14() {
		return new SimpleDateFormat(formatTime14Str).format(new Date());
	}

	public static String datetime14(Date date) {
		return new SimpleDateFormat(formatTime14Str).format(date);
	}

	public static String datetime14(long t) {
		return new SimpleDateFormat(formatTime14Str).format(new Date(t));
	}
	
	public static Timestamp formatString2Timestamp(String date,String format) throws ParseException {
		if(null==date||("").equals(date))return null;
		if(null==format||("").equals(format))return null;
		return new Timestamp(formatStringToDate(date,format).getTime());
	}
	public static Date formatStringToDate(String date,String format) throws ParseException {
		if(null==date||("").equals(date))return null;
		if(null==format||("").equals(format))return null;
		SimpleDateFormat format2 = new SimpleDateFormat(format);
		Date newDate = format2.parse(date);
		return newDate;
	}
	/**
	 * 20071231转换为2007-12-31
	 * @param date
	 * @return
	 */
	public static String date8(String date){
		if(null==date)return null;
		date = date.trim();
		if(date.length()!=8)return null;
		else return date.substring(0,4)+"-"+date.substring(4,6)+"-"+date.substring(6,8);
	}
	
	/**
	 * 格式化日期
	 * @param orderInfoList
	 * @
	 */
	public static String formatDate(Date date)  {
		if(date == null) {
			return null;
		}
		SimpleDateFormat newformat = new SimpleDateFormat("yyyy-MM-dd"); //需要展现的时间格式
		return newformat.format(date);
		
	}
	
	public static String formatDate(Date date, String format) {
		if(date == null) {
			return null;
		}
		SimpleDateFormat newformat = new SimpleDateFormat(format); //需要展现的时间格式
		return newformat.format(date);
	}
	
	public static Date addMonth(Date date, int month) {		
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.MONTH, month);
		return calendar.getTime();
	}
	public static String addMonth(String orderDate, int month) throws ParseException {
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
		Calendar calendar = Calendar.getInstance();
		Date paramDate = format.parse(orderDate);		
		calendar.setTime(paramDate);
		calendar.add(Calendar.MONTH, month);
		return date8(calendar.getTime());
	}
	public static Date addDay(Date date, int day) {		
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.DATE, day);
		return calendar.getTime();
	}
	
	public static Date addSecond(Date date, int second) {		
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.SECOND, second);
		return calendar.getTime();
	}
	
	public static Date addYear(Date date, int year) {		
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.YEAR, year);
		return calendar.getTime();
	}
	
	public static Date getPreDate(Date date, int month) throws ParseException {	
		Date tempDate = addMonth(date,month);
		SimpleDateFormat format = new SimpleDateFormat(formatDay8Str);
		String preDayStr = format.format(tempDate);
		return formatStringToDate(preDayStr, formatDay8Str);
	}
	
	public static String getYear(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar.get(Calendar.YEAR) + "";
	}
	
	public static String conversFormat(String time, String srcFormat, String targetFormat) throws ParseException  {
		Date srcDate = formatStringToDate(time.trim(), srcFormat);
		String result = formatDate(srcDate, targetFormat); //交易日期 
		return result;
	}
	
	 /**
	 * 判断是否是周末
	 * @param date 表示日期的字符串，比如20100424
	 * @param pattern 描述日期和时间格式的模式，比如yyyyMMdd
	 * @return
	 * @throws ParseException 
	 * @throws ParseException
	 */
    public static boolean isWeekend(String date,String pattern) throws ParseException  {
    	SimpleDateFormat df = new SimpleDateFormat(pattern);
	    Date time = df.parse(date);
	    Calendar cal = Calendar.getInstance();
	    cal.setTime(time);
		
	    int day = cal.get(Calendar.DAY_OF_WEEK);
	    
	    if (day == Calendar.SATURDAY || day == Calendar.SUNDAY){
	    	return true;
	    }
	    else{
	    	return false;
	    }
    }
    
    public static int getWeek(Date date)  {
    	 Calendar cal = Calendar.getInstance();
 	    cal.setTime(date);
 		
 	    int day = cal.get(Calendar.DAY_OF_WEEK);
 	    return day;
	}
    
    
    public static boolean isWeekend(Date date)  {
	    Calendar cal = Calendar.getInstance();
	    cal.setTime(date);
		
	    int day = cal.get(Calendar.DAY_OF_WEEK);
	    
	    if (day == Calendar.SATURDAY || day == Calendar.SUNDAY){
	    	return true;
	    }
	    else {
	    	return false;
	    }
    }
	
	/**
	 * 获取距当前日期n+1个月的年信息，如当前日期为2009-02-03，n=3，则结果为{2008,2009}
	 * 
	 * @param monthCount
	 * @return
	 */
	public static String[] getYearList(int monthCount) {
		if (monthCount > 0)
			monthCount = 0 - monthCount;// 保证是向前推
		Calendar cal = Calendar.getInstance();
		int year1 = cal.get(Calendar.YEAR);
		cal.add(Calendar.MONTH, monthCount);// 实际推了n+1月
		int year2 = cal.get(Calendar.YEAR);
		String[] retVal = new String[year1 - year2 + 1];
		for (int i = 0; year1 >= year2; year1--, i++) {
			retVal[i] = year1 + "";
		}
		return retVal;
	}
	
	/**
	 * 将日期格式的字符串格式化成指定的日期格式
	 * 
	 * @param dateStr
	 *            源日期字符串
	 * @param formatStr1
	 *            源日期字符串日期格式
	 * @param formatStr2
	 *            新日期字符串日期格式
	 */
	public static String formatDateStringToString(String dateStr,
			String formatStr1, String formatStr2) {
		try {
			if (null == dateStr)
				return null;
			SimpleDateFormat format = new SimpleDateFormat(formatStr1);
			Date date = format.parse(dateStr);
			return new SimpleDateFormat(formatStr2).format(date);
		} catch (Exception ex) {
			return null;
		}

	}
	/**
	 * 将日期转换为新的格式
	 * @param dateStr
	 * @param formatStr1
	 * @param intervalDate
	 * @param formatStr2
	 * @return
	 * @see:
	 */
	public static String formatDateStringToString(String dateStr, String formatStr1, int intervalDate, String formatStr2) {
		try {
			if (null == dateStr)
				return null;
			SimpleDateFormat format = new SimpleDateFormat(formatStr1);
			Date date = format.parse(dateStr);
			Date newDate = addDay(date, intervalDate);
			return new SimpleDateFormat(formatStr2).format(newDate);
		} catch (Exception ex) {
			return null;
		}
		
	}
	
	/**
	 * 格式化时间戳为字符串
	 * 
	 * @param date
	 * @param format
	 * @return
	 */
	public static String formatTimestamp2String(Timestamp date, String format) {
		if (null == date)
			return null;
		if (null == format || ("").equals(format))
			return null;
		return new SimpleDateFormat(format).format(date);
	}
	/**
	 * 获取查询日期的区间
	 * 例如：endDate是20110713，interval是3，表示三个月前，则返回 stateDate= 20110413 endDate=20110713的map
	 * @param endDate 结束日期
	 * @param interval 时间间隔
	 * @return
	 * @
	 */
	public static Map<String, String> getQryDateInterval(Date endDate, int intervalMonth, String format)  {
		int tempInt = 0 - intervalMonth;
		Date preDate = addMonth(endDate, tempInt);
		String stateDateStr = formatDate(preDate, format);
		String endDateStr = formatDate(endDate, format);
		Map<String, String> resultMap = new HashMap<String, String>();
		resultMap.put(CommonConsts.START_DATE, stateDateStr);
		resultMap.put(CommonConsts.END_DATE, endDateStr);
		return resultMap;
	}

	
	public static void validateDateInterval(String startDateStr, String endDateStr, int intervalMonth, String format) throws BaseException {
		startDateStr = StringUtil.trim(startDateStr);
		endDateStr = StringUtil.trim(endDateStr);
		format = StringUtil.trim(format);
		if ("".equals(startDateStr)) {
			//如果开始或结束日期为空，返回-1;
			throw new BaseException("开始日期不能为空");
		}
		
		if ("".equals(endDateStr)) {
			//如果开始或结束日期为空，返回-1;
			throw new BaseException("结束日期不能为空");
		}
		
		Date startDate = null;
		Date endDate = null;
		
		try {
			startDate = formatStringToDate(startDateStr, format);
		} catch (ParseException e1) {
			throw new BaseException("开始日期格式不正确");
		}
		
		try {
			endDate = formatStringToDate(endDateStr, format);
		} catch (ParseException e1) {
			throw new BaseException("结束日期格式不正确");
		}
		
		if (startDate.after(endDate)) {
			//如果结束日期在开始日期之前，返回2
			throw new BaseException("结束日期不能在开始日期之前");
		}
		
		Date nowDate = new Date();
		Date preDate = addMonth(nowDate, -intervalMonth);
		
		if (endDate.after(nowDate)) {
			//结束日期不能超过当前日期
			throw new BaseException("结束日期不能超过当前日期");
		}
		
		if (startDate.before(preDate)) {
			//开始日期不在日期范围之内
			throw new BaseException("开始日期不在日期范围之内");
		}
	}
	
	/**
	 * 
	 * desc:日期格式以及跨度范围的校验
	 * @author liuguangjun, Aug 8, 2013 3:47:08 PM
	 * @param startDateStr  开始日期
	 * @param endDateStr	结束日期
	 * @param intervalMonth 开始和今天的跨度月
	 * @param spanMonth 开始和结束日期的跨度月
	 * @param format	日期格式
	 * @throws BaseException
	 */
	public static void validateDateInterval(String startDateStr, String endDateStr, int intervalMonth,int spanMonth, String format) throws BaseException {
		startDateStr = StringUtil.trim(startDateStr);
		endDateStr = StringUtil.trim(endDateStr);
		format = StringUtil.trim(format);
		if ("".equals(startDateStr)) {
			//如果开始或结束日期为空，返回-1;
			throw new BaseException(RetCode.REQPARAM_ERR,"开始日期不能为空");
		}
		
		if ("".equals(endDateStr)) {
			//如果开始或结束日期为空，返回-1;
			throw new BaseException(RetCode.REQPARAM_ERR,"结束日期不能为空");
		}
		
		Date startDate = null;
		Date endDate = null;
		
		try {
			startDate = formatStringToDate(startDateStr, format);
		} catch (ParseException e1) {
			throw new BaseException(RetCode.REQPARAM_ERR,"开始日期格式不正确");
		}
		
		try {
			endDate = formatStringToDate(endDateStr, format);
		} catch (ParseException e1) {
			throw new BaseException(RetCode.REQPARAM_ERR,"结束日期格式不正确");
		}
		
		if (startDate.after(endDate)) {
			//如果结束日期在开始日期之前，返回2
			throw new BaseException(RetCode.REQPARAM_ERR,"结束日期不能早于开始日期");
		}
		
		Date nowDate = new Date();
		
		if (endDate.after(nowDate)) {
			//结束日期不能超过当前日期
			throw new BaseException(RetCode.REQPARAM_ERR,"结束日期不能晚于当前日期");
		}

		Date preDate = addDay(nowDate, -intervalMonth*30);
		if (startDate.before(preDate)) {
			//开始日期不在今日之前n月范围之内
			throw new BaseException(RetCode.REQPARAM_ERR,"开始日期必须在今日之前"+intervalMonth*30+"天以内");
		}
		
		Date preDate2 = addMonth(endDate, -spanMonth);
		if (startDate.before(preDate2)) {
			//开始日期与结束日期跨度不在日期范围之内
			throw new BaseException(RetCode.REQPARAM_ERR,"开始日期与结束日期跨度必须在"+spanMonth+"月以内");
		}
	}
	
	/**
//	 * "2013-05-09 19:05:20:5555" 转换成 2013-05-09 19:05:20
	 * @return
	 */
	public static String formateDate(String dateStr,String formate){
		SimpleDateFormat sf = new SimpleDateFormat(formate);
		try {
			return sf.format(sf.parse(dateStr));
		} catch (ParseException e) {
			return dateStr;
		}
	}
	/**
	 * 
	 * description: 判断当前时间是否为19点以后
	 * @param endDate
	 * @param amount
	 * @return
	 */
	public static boolean nowIsNight() {
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		int i =cal.get(Calendar.HOUR_OF_DAY);
		return i >18;
	}
	public static String datetime10() {
		return new SimpleDateFormat(formatTime10Str).format(new Date());
	}
	/**
	 * 获取两日期之间的年月
	 * @param startDate
	 * @param endDate
	 * @return
	 * @throws ParseException 
	 */
	public static List<String> getYearAndMonth(String startDate, String endDate) throws ParseException {
		List<String> list = new ArrayList<String>();
		String temp = startDate;
		
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
		
		do {
			list.add(temp.substring(2, 6));

			Date tempDate = format.parse(temp);
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(tempDate);
			calendar.add(Calendar.MONTH, 1);
			temp = format.format(calendar.getTime());			
		} while ((temp.substring(0, 6)).compareTo(endDate.substring(0, 6)) <= 0);
				
		return list;
	}
	/**
	 * 如果tradeDate的前一天是上月，则取前一天的日期；
	 * 如果tradeDate的后一天日期为下月，且下月年月不大于当前年月，则返回后一天的日期；
	 * 否则，返回空
	 * @param tradeDate
	 * @return
	 * @throws ParseException 
	 */
	public static String getBeforeMonthOrNextMonth(String tradeDate) throws ParseException {
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
		
		Calendar calendar = Calendar.getInstance();
		String nowDate = format.format(calendar.getTime());
		
		Date paramDate = format.parse(tradeDate);
		calendar.setTime(paramDate);
		calendar.add(Calendar.DAY_OF_YEAR, -1);
		String tradeDateOneDayBeforeString = format.format(calendar.getTime());
		
		calendar.setTime(paramDate);
		calendar.add(Calendar.DAY_OF_YEAR, 1);
		String tradeDateOneDayLaterString = format.format(calendar.getTime());
		
		if (!tradeDate.substring(0, 6).equals(tradeDateOneDayBeforeString.substring(0, 6))) {
			return tradeDateOneDayBeforeString;
		} else if (!tradeDate.substring(0, 6).equals(tradeDateOneDayLaterString.substring(0, 6)) && 
				nowDate.substring(0, 6).compareTo(tradeDateOneDayLaterString.substring(0, 6)) >= 0) {
			return tradeDateOneDayLaterString;
		} else {
			return null;
		}
	}
	
	public static int getMonth(Date date)  {
    	Calendar cal = Calendar.getInstance();
	    cal.setTime(date);
	    return cal.get(Calendar.MONTH)+1;
	}
	public static Timestamp getTimestamp(String time) throws ParseException {
		SimpleDateFormat format = new SimpleDateFormat(
				"yyyyMMdd HH:mm:ss.SSSSSS");
		return new Timestamp(format.parse(time).getTime());
	}
	/**
	 * 如果tradeDate的后面第七天为下个月，则去下个月的月表；
	 * 否则，返回空
	 * @param tradeDate
	 * @return
	 * @throws ParseException 
	 */
	public static String getNextMonth(String tradeDate) throws ParseException {
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
		
		Calendar calendar = Calendar.getInstance();
		
		Date paramDate = format.parse(tradeDate);		
		calendar.setTime(paramDate);
		calendar.add(Calendar.DAY_OF_YEAR, 7);
		String tradeDateSeverDayLaterString = format.format(calendar.getTime());
		
		if (!tradeDate.substring(0, 6).equals(tradeDateSeverDayLaterString.substring(0, 6))) {
			return tradeDateSeverDayLaterString;
		} else {
			return null;
		}
	}
	/**
	 * 
	 * <br>description : 校验截止日期是否小于起始日期
	 * @param startDateStr    起始日期
	 * @param endDateStr      结束日期
	 * @param formatStr   	      日期格式化
	 * @return
	 * @author      zjk
	 * @version     1.0
	 * @date        Feb 9, 20122:33:07 PM
	 */
	public static boolean checkDateBefore(String startDateStr,String endDateStr,String formatStr){
		SimpleDateFormat format = new SimpleDateFormat(formatStr);
		try {
			Date startDate = format.parse(startDateStr);
			Date endDate = format.parse(endDateStr);
			return startDate.getTime()<=endDate.getTime();
		} catch (ParseException e) {
			return false;
		}
	}
	public static Date addHour(Date now, int amount) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(now);
		cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 3);
		return cal.getTime();
	}
	
	public static String timestampToStr(Timestamp time, String format) {
		DateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(time);
	}
	
	/**
	 * 日期加减天数
	 * 
	 * @param dateStr YYYYMMDD 日期
	 * @param days 天数
	 * @return
	 */
	public static String addDays(String dateStr, int days){
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.YEAR, Integer.parseInt(dateStr.substring(0, 4)));
		calendar.set(Calendar.MONTH, Integer.parseInt(dateStr.substring(4, 6))-1);
		calendar.set(Calendar.DATE, Integer.parseInt(dateStr.substring(6, 8)));
		calendar.add(Calendar.DATE, days);
        return DateTimesUtil.date8(calendar.getTime());
	}
	
	/**
	 * 日期加减月数
	 * 
	 * @param yearMonth YYYYMM 年月
	 * @param months 月数
	 * @return
	 */
	public static String addMonths(String yearMonth, int months){
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.YEAR, Integer.parseInt(yearMonth.substring(0, 4)));
		calendar.set(Calendar.MONTH, Integer.parseInt(yearMonth.substring(4, 6))-1);
		calendar.set(Calendar.DATE, 1);
		calendar.add(Calendar.MONTH, months);
        return DateTimesUtil.date8(calendar.getTime()).substring(0,6);
	}
	
	/**
	 * 获得某月的天数
	 * 
	 * @param yearMonth 年月
	 * @return
	 */
	public static int getMaxDaysOfMonth(String yearMonth){
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.YEAR, Integer.parseInt(yearMonth.substring(0, 4)));
		calendar.set(Calendar.MONTH, Integer.parseInt(yearMonth.substring(4, 6))-1);
		calendar.set(Calendar.DATE, 1);
		int daysOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
		return daysOfMonth;
	}
	
	@SuppressWarnings("unused")
	public static void main(String[] args) {
//		Date now = new Date();
//		Date pre = getPreDate(now, -3);
//		SimpleDateFormat format = new SimpleDateFormat(formatTime24Str);
//		System.out.println(format.format(pre));
//		Date now = new Date();
//		System.out.println(getYear(now));
//		try {
//			System.out.println(isWeekend(now));
//			System.out.println(isWeekend("20110131", DateTimesUtil.formatDay8Str));
//			System.out.println(getWeek(now) + "  " + Calendar.SUNDAY);
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		
//		String startDateStr = "20110101";
//		String endDateStr = "20110813";
//		int intervalMonth = 3;
//		try {
//			DateTimesUtil.validateDateInterval(startDateStr, endDateStr, intervalMonth, DateTimesUtil.formatDay8Str);
//		} catch (BaseException e) {
//			System.out.println(e.getMessage());
//		}
		System.out.println("****************************"+date12());
//		String startInTime = "2012-07-01 11:30:00";
//		String result = formatDateStringToString(startInTime, formatTime16Str, -1, formatDay8Str);
//		try {
//			Date result1 = formatStringToDate(startInTime, formatTime18Str);
//			System.out.println(date8(result1));
//			result1=addDay(new Date(), -91);
//			System.out.println(date8(result1));
//		} catch (ParseException e1) {
//			e1.printStackTrace();
//		}//(startInTime, formatTime16Str, -1, formatDay8Str);
//		datetime10();
		try {
//			String dateTimeStr=DateTimesUtil.datetime10();
//			String seriaStr = SerialUtil.getSerialFromFile("tradeno", 3);
//			String tableflag =String.valueOf(DateTimesUtil.getWeek(new Date()));
//			String tradeNo=dateTimeStr+seriaStr+tableflag;
//			System.out.println(tradeNo);
			DateTimesUtil.validateDateInterval("20150511", "20150611", 1, DateTimesUtil.formatDay8Str);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	/**
	 * 获取系统时间
	 * @return
	 */
	public static String getDateTime(){
		return new SimpleDateFormat("yyyyMMdd").format(new Date());
	}
	
	
	/**
	 * 日期转换
	 * @param date
	 * @return "yyyyMM"
	 */
	public static String dateYm6(Date date) {
		return new SimpleDateFormat(formatDay6Str).format(date);
	}
	
	/**
	 * 日期转换
	 * @param date
	 * @return "yyyy-MM"
	 */
	public static String dateYm7(Date date) {
		return new SimpleDateFormat(formatDay7Str).format(date);
	}
	
	/**
	 * 日期转换
	 * @param date
	 * @return "yyyy-MM-dd"
	 */
	public static String date10(String date) {
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.YEAR, Integer.parseInt(date.substring(0, 4)));
		calendar.set(Calendar.MONTH, Integer.parseInt(date.substring(4, 6))-1);
		calendar.set(Calendar.DATE, Integer.parseInt(date.substring(6, 8)));
		return new SimpleDateFormat(formatDay10Str).format(calendar.getTime());
	}
	
	/**
	 * 日期转换
	 * @param date yyyymmdd
	 * @param time hhmmss
	 * @return "yyyy-MM-dd hh:mm:ss"
	 */
	public static String date18(String date, String time) {
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.YEAR, Integer.parseInt(date.substring(0, 4)));
		calendar.set(Calendar.MONTH, Integer.parseInt(date.substring(4, 6))-1);
		calendar.set(Calendar.DATE, Integer.parseInt(date.substring(6, 8)));
		calendar.set(Calendar.HOUR, Integer.parseInt(time.substring(0, 2)));
		calendar.set(Calendar.MINUTE, Integer.parseInt(time.substring(2, 4)));
		calendar.set(Calendar.SECOND, Integer.parseInt(time.substring(4, 6)));
		return new SimpleDateFormat(formatTime18Str).format(calendar.getTime());
	}
}
